<!DOCTYPE html>
<html lang="zh-cn" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, minimum-scale=1.0">
    <meta name="generator" content="Hugo 0.120.4">
    <meta name="generator" content="Relearn 5.23.2">
    <meta name="description" content="操作系统-数据结构与算法-云计算-ARM64-C/C&#43;&#43;-Go">
    <meta name="author" content="Jiang Kun">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="使用hugo搭建静态网站 :: 笔记">
    <meta name="twitter:description" content="操作系统-数据结构与算法-云计算-ARM64-C/C&#43;&#43;-Go">
    <meta property="og:title" content="使用hugo搭建静态网站 :: 笔记">
    <meta property="og:description" content="操作系统-数据结构与算法-云计算-ARM64-C/C&#43;&#43;-Go">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://dipperkun.gitee.io/static-website/howto-use-hugo/">
    <meta property="og:site_name" content="笔记">
    <title>使用hugo搭建静态网站 :: 笔记</title>
    <link href="https://dipperkun.gitee.io/static-website/howto-use-hugo/" rel="canonical" type="text/html" title="使用hugo搭建静态网站 :: 笔记">
    <link href="../../static-website/howto-use-hugo/index.xml" rel="alternate" type="application/rss+xml" title="使用hugo搭建静态网站 :: 笔记">
    <link href="../../images/favicon.png?1701141428" rel="icon" type="image/png">
    <!-- https://github.com/filamentgroup/loadCSS/blob/master/README.md#how-to-use -->
    <link href="../../css/fontawesome-all.min.css?1701141429" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="../../css/fontawesome-all.min.css?1701141429" rel="stylesheet"></noscript>
    <link href="../../css/nucleus.css?1701141429" rel="stylesheet">
    <link href="../../css/auto-complete.css?1701141429" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="../../css/auto-complete.css?1701141429" rel="stylesheet"></noscript>
    <link href="../../css/perfect-scrollbar.min.css?1701141429" rel="stylesheet">
    <link href="../../css/fonts.css?1701141429" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="../../css/fonts.css?1701141429" rel="stylesheet"></noscript>
    <link href="../../css/theme.css?1701141429" rel="stylesheet">
    <link href="../../css/theme-zen-light.css?1701141429" rel="stylesheet" id="R-variant-style">
    <link href="../../css/variant.css?1701141429" rel="stylesheet">
    <link href="../../css/print.css?1701141429" rel="stylesheet" media="print">
    <link href="../../css/format-print.css?1701141429" rel="stylesheet">
    <link href="../../css/ie.css?1701141429" rel="stylesheet">
    <script src="../../js/url.js?1701141429"></script>
    <script src="../../js/variant.js?1701141429"></script>
    <script>
      // hack to let hugo tell us how to get to the root when using relativeURLs, it needs to be called *url= for it to do its magic:
      // https://github.com/gohugoio/hugo/blob/145b3fcce35fbac25c7033c91c1b7ae6d1179da8/transform/urlreplacers/absurlreplacer.go#L72
      window.index_js_url="../../index.search.js";
      var root_url="../../";
      var baseUri=root_url.replace(/\/$/, '');
      // translations
      window.T_Copy_to_clipboard = '复制到剪贴板';
      window.T_Copied_to_clipboard = '复制到剪贴板！';
      window.T_Copy_link_to_clipboard = '将链接复制到剪贴板';
      window.T_Link_copied_to_clipboard = '链接复制到剪贴板！';
      window.T_Reset_view = '重置视图';
      window.T_View_reset = '查看重置！';
      window.T_No_results_found = '找不到\u0022{0}\u0022的结果';
      window.T_N_results_found = '为\u0022{0}\u0022找到 {1} 个结果';
      // some further base stuff
      var baseUriFull='https:\/\/dipperkun.gitee.io/';
      window.variants && variants.init( [ 'zen-light', 'zen-dark' ] );
    </script>
  </head>
  <body class="mobile-support print disableInlineCopyToClipboard" data-url="../../static-website/howto-use-hugo/">
    <div id="R-body" class="default-animation">
      <div id="R-body-overlay"></div>
      <nav id="R-topbar">
        <div class="topbar-wrapper">
          <div class="topbar-sidebar-divider"></div>
          <div class="topbar-area topbar-area-start" data-area="start">
            <div class="topbar-button topbar-button-sidebar" data-content-empty="disable" data-width-s="show" data-width-m="hide" data-width-l="hide">
              <button class="topbar-control" onclick="toggleNav()" type="button" title="导航 (CTRL&#43;ALT&#43;n)">
                <i class="fa-fw fas fa-bars"></i>
              </button>
            </div>
          </div>
          <ol class="topbar-breadcrumbs breadcrumbs highlightable" itemscope itemtype="http://schema.org/BreadcrumbList"><li
            itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement"><a itemprop="item" href="../../"><span itemprop="name">[生活/工作/学习]</span></a><meta itemprop="position" content="1">&nbsp;>&nbsp;</li><li
            itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement"><a itemprop="item" href="../../static-website/"><span itemprop="name">静态网站</span></a><meta itemprop="position" content="2">&nbsp;>&nbsp;</li><li
            itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement"><span itemprop="name">使用hugo搭建静态网站</span><meta itemprop="position" content="3"></li>
          </ol>
          <div class="topbar-area topbar-area-end" data-area="end">
          </div>
        </div>
      </nav>
      <div id="R-main-overlay"></div>
      <main id="R-body-inner" class="highlightable default" tabindex="-1">
        <div class="flex-block-wrapper">
          <article class="default">
            <header class="headline">
<div class=" taxonomy-tags term-list cstyle  tags" title="Tags" style="--VARIABLE-TAGS-BG-color: var(--INTERNAL-TAG-BG-color);">
  <ul>
    <li><a class="term-link" href="../../tags/hugo/">hugo</a></li>
    <li><a class="term-link" href="../../tags/markdown/">markdown</a></li>
    <li><a class="term-link" href="../../tags/shortcodes/">shortcodes</a></li>
    <li><a class="term-link" href="../../tags/themes/">themes</a></li>
  </ul>
</div>
            </header>
<h1 id="使用hugo搭建静态网站">使用hugo搭建静态网站</h1>

<h2 id="安装-hugo">安装 hugo</h2>
<p>下载并安装hugo</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">wget https://ghps.cc/https://github.com/gohugoio/hugo/releases/download/v0.120.4/hugo_extended_0.120.4_linux-amd64.deb
</span></span><span class="line"><span class="cl">sudo apt instatll ./hugo_extended_0.120.4_linux-amd64.deb</span></span></code></pre></div><p>生成网站代码骨架</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">hugo new site ./notebook
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> ./notebook</span></span></code></pre></div><h2 id="下载主题themes">下载主题(themes)</h2>
<p>在 <a href="https://gohub.io" target="_blank">hugo</a>官网选择合适的主题，放在网站代码骨架的 <code>themes</code> 文件夹下。本网站采用 <a href="https://mcshelby.github.io/hugo-theme-relearn" target="_blank">Relearn</a>主题。</p>
<h2 id="配置">配置</h2>
<p>根据主题的示例站点配置文件 <code>config.toml</code>，该文件位于代码骨架的根目录下。</p>
<h2 id="编写文章">编写文章</h2>
<p>网站首页文件为 <code>content/_index.md</code>。</p>
<p>生成形式为 <code>chapter</code> 的内容。</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">hugo new --kind chapter chapter01/_index.md
</span></span><span class="line"><span class="cl">vim content/chapter01/_index.md</span></span></code></pre></div><p>生成文章内容。</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">hugo new chapter01/article001/_index.md
</span></span><span class="line"><span class="cl">vim content/chapter01/article001/_index.md</span></span></code></pre></div><h2 id="测试与发布">测试与发布</h2>
<p>测试</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">hugo server --disableFastRender -D</span></span></code></pre></div><p>发布
最终生成的网站 <code>html</code> 代码位于 <code>public</code> 目录。</p>
<div class="wrap-code highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">hugo</span></span></code></pre></div>
            <footer class="footline">
<div class=" taxonomy-categories term-list cstyle  " title="Categories" style="--VARIABLE-TAGS-BG-color: var(--INTERNAL-TAG-BG-color);">
  <i class="fa-fw fas fa-layer-group"></i>
  <ul>
    <li><a class="term-link" href="../../categories/%E5%B7%A5%E5%85%B7/">工具</a></li>
  </ul>
</div>
            </footer>
          </article>

        </div>
      </main>
    </div>
    <script src="../../js/clipboard.min.js?1701141429" defer></script>
    <script src="../../js/perfect-scrollbar.min.js?1701141429" defer></script>
    <script src="../../js/theme.js?1701141429" defer></script>
  </body>
</html>
